package com.ccb.sc.goods.controller;

import com.ccb.sc.common.bind.annotation.Limit;
import com.ccb.sc.common.bind.response.ResBody;
import com.ccb.sc.common.bind.vo.KeyValueIconVo;
import com.ccb.sc.common.modules.goods.service.ICategoryService;
import com.ccb.sc.common.modules.goods.vo.CategoryTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ken
 * @version 1.0
 * @date 2020-09-21
 */
@RestController
@Api(value = "分类管理", tags = "分类管理")
@RequestMapping("/app/category")
public class AppCategoryController {

    private ICategoryService categoryService;

    @Limit(period = 5, count = 5)
    @GetMapping("/list")
    @ApiOperation(value = "商品分类列表", response = KeyValueIconVo.class, responseContainer = "list")
    public ResBody<?> list(@ApiParam(value = "上级id") @RequestParam(required = false) Long parentId, @RequestParam Long type) {
        List<KeyValueIconVo> list = this.categoryService.findAll(parentId, type);
        return ResBody.success(list);
    }

    @Limit(period = 5, count = 5)
    @GetMapping("/tree")
    @ApiOperation(value = "商品分类树", response = CategoryTreeVo.class, responseContainer = "list")
    public ResBody<?> tree(@RequestParam Integer type) {
        List<CategoryTreeVo> list = this.categoryService.getAllCategoryTree(type);
        return ResBody.success(list);
    }

    @Autowired
    public void setCategoryService(ICategoryService categoryService) {
        this.categoryService = categoryService;
    }
}
